package com.yanwq.sayhi.rest;

import com.yanwq.sayhi.bean.ClubVip;
import com.yanwq.sayhi.exception.ExResponse;
import com.yanwq.sayhi.service.ClubVipService;
import com.yanwq.sayhi.tool.JSONResultTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作者：yanweiqiang。
 * 日期：2016/6/16 0016。
 */
@RestController
@RequestMapping(path = "/clubVip")
public class ClubVipRest {

    @Autowired
    private ClubVipService service;

    @RequestMapping(path = "/apply", method = RequestMethod.POST)
    public ClubVip apply(@RequestBody ClubVip clubVip) {
        ClubVip result = service.apply(clubVip);
        if (result == null) {
            throw new ExResponse(1001, "口令错误");
        }
        return result;
    }

    @RequestMapping(path = "/refuse", method = RequestMethod.POST)
    public ClubVip refuse(@RequestBody ClubVip clubVip) {
        return service.refuse(clubVip);
    }

    @RequestMapping(path = "/pass", method = RequestMethod.POST)
    public ClubVip pass(@RequestBody ClubVip clubVip) {
        return service.pass(clubVip);
    }

    @RequestMapping(path = "/create", method = RequestMethod.POST)
    public ClubVip create(@RequestBody ClubVip clubVip) {
        return service.create(clubVip);
    }

    @RequestMapping(path = "/remove", method = RequestMethod.POST)
    public String remove(@RequestParam long userId, long clubId) {
        service.remove(userId, clubId);
        return JSONResultTool.makeJSONResult("已退出");
    }


    @RequestMapping(path = "/list/user", method = RequestMethod.GET)
    public List<ClubVip> listByUser(@RequestParam long userId, @RequestParam int page, @RequestParam int size) {
        return service.listByUser(userId, page, size);
    }

    @RequestMapping(path = "/list/club", method = RequestMethod.GET)
    public List<ClubVip> listByClub(@RequestParam long clubId, @RequestParam int page, int size) {
        return service.listByClub(clubId, page, size);
    }
}